<template>
  <el-dialog
      :title="title"
      v-model="dialogVisible"
      width="70%"
      append-to-body
      modal-append-to-body
      v-loading="loading"
      @close="handleClose">

    <start-act-start ref="startActStart"
                     :user-id="startConfig.userId"
                     start-user-type="admin_user"
                     @loadProcDetailSuccess="loadProcDetailSuccess"
                     :startApplySuccess="startApplySuccess"
    ></start-act-start>

    <template #footer>
        <span class="dialog-footer">
            <el-button @click="handleClose">取 消</el-button>
            <el-button @click="clear">清 空</el-button>
            <el-button type="primary" @click="submit">提交</el-button>
          </span>
    </template>

  </el-dialog>

</template>

<script>


import StartActStart from "./startActStart.vue";
import useUserStore from "@/stores/useUserStore";

export default {
  name: "startActDialog",
  components: {StartActStart},
  computed: {
    title() {
      if (!this.model)
        return "加载中"
      if (!this.model.procName) {
        return "加载中"
      }
      return '请填写' + this.model.procName + '表'
    }
  },
  data() {
    return {
      dialogVisible: false,
      model: {},
      loading: true,
      userId: null,
      startConfig: null,
    }
  },
  created() {
    this.userId=useUserStore().userInfo.id
     
  },
  methods: {
    show(config) {
      this.startConfig = config;
      this.dialogVisible = true;
      this.$nextTick(() => {
        this.$refs.startActStart.init(this.startConfig.modelKey)
      })
    },
    loadProcDetailSuccess(data) {
      this.model = data;
      console.log("data", data)
    },
    clear() {
      if (this.$refs.startActStart) {
        this.$refs.startActStart.clear();
      }

    },
    startApplySuccess() {
      this.$message.success("提交成功")
      this.$emit("submitSuccess")
      this.handleClose();
    },
    handleClose() {
      this.clear();

      this.model = null;
      this.dialogVisible = false;
      this.loading = true
      this.$emit("close")
    },
    submit() {
      this.$refs.startActStart.startAct();
    }
  }
}
</script>

<style scoped>

</style>
